package com.wxapp.market.service.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wxapp.common.constant.base.IBaseController;
import com.wxapp.common.constant.pojo.vm.ResultVm;
import com.wxapp.common.constant.pojo.vo.UserVo;
import com.wxapp.common.core.annotation.User;
import com.wxapp.market.api.pojo.vm.coupon.PCouponDetailVm;
import com.wxapp.market.api.pojo.vm.coupon.PCouponGoodsVm;
import com.wxapp.market.api.pojo.vm.coupon.PCouponPageVm;
import com.wxapp.market.api.pojo.vo.coupon.QCouponAddVo;
import com.wxapp.market.api.pojo.vo.coupon.QCouponPageVo;
import com.wxapp.market.api.pojo.vo.coupon.QCouponUpdateVo;
import com.wxapp.market.service.service.CouponService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lgl
 * @Description 优惠券管理
 * @Datetime 2022/7/4 16:12
 * @Modified By
 */
@RestController
@Tag(name = "优惠券管理")
@RequestMapping("coupon")
@RequiredArgsConstructor
public class CouponController extends IBaseController {
    private final CouponService couponService;

    @PostMapping("add")
    @Operation(summary ="添加优惠券")
    public ResultVm<String> add(@RequestBody @Validated QCouponAddVo qCouponAddVo, @Schema(hidden = true) @User UserVo userVo) {
        return couponService.add(qCouponAddVo, userVo);
    }

    @PutMapping("update")
    @Operation(summary ="更新优惠券")
    public ResultVm<String> update(@RequestBody @Validated QCouponUpdateVo qCouponUpdateVo, @Schema(hidden = true) @User UserVo userVo) {
        return couponService.update(qCouponUpdateVo, userVo);
    }

    @PostMapping("page")
    @Operation(summary ="获取优惠券列表")
    public ResultVm<Page<PCouponPageVm>> getPage(@RequestBody QCouponPageVo qCouponPageVo) {
        return couponService.getPage(qCouponPageVo);
    }

    @DeleteMapping("delete/{id}")
    @Operation(summary ="删除优惠券")
    public ResultVm<String> delete(@PathVariable String id) {
        return couponService.delete(id);
    }

    @GetMapping("/detail/{id}")
    @Operation(summary ="获取优惠券详细信息")
    public ResultVm<PCouponDetailVm> detail(@PathVariable String id) {
        return couponService.detail(id);
    }

    @PutMapping("/addGoods/{id}")
    @Operation(summary ="优惠券绑定商品")
    public ResultVm<String> addGoods(@PathVariable String id, @RequestBody List<String> productId) {
        return couponService.addGoods(id,productId);
    }

    @GetMapping("/getGoods/{id}")
    @Operation(summary ="获取优惠券绑定商品")
    public ResultVm<List<PCouponGoodsVm>> getGoods(@PathVariable String id) {
        return couponService.getGoods(id);
    }
}
